
import Dialog4Setting from './Dialog4Setting';
import SettingDialog from './SettingDialog';
import {WeaLocaleProvider} from 'ecCom';
const getLabel = WeaLocaleProvider.getLabel;
class ToolBar extends React.Component {
  constructor() {
    super();
    this.state = {
      dgvisible: false
    }
  }
  setdgVisible = (bool) => {
    this.setState( {
      dgvisible: bool
    })
  }
  onOk = (data) =>{
    const { doSave } = this.props;
    this.setdgVisible(false);
    doSave(data);
  }
  onSettingBtnClick = () => {
    const { onSettingBtnClick } = this.props;
    onSettingBtnClick();
    this.setdgVisible(true);
  }
  render() {
    const { settingData=[], moreBtnClick, toolSetting, type, doRefresh, title, dialogHeight } = this.props;
    const { refresh=false, setting=false, more=false} = {refresh: false,setting:false, more: false,...toolSetting};
    let dgComponent = null;
    if(this.state.dgvisible){
      // dgComponent = (
      //   <Dialog4Setting 
      //     title={title}
      //     type={type}
      //     settingData={settingData} 
      //     dialogHeight={dialogHeight}
      //     onCancel={this.setdgVisible.bind(this, false)}
      //     onOk={this.onOk}
      //   />
      // )
       dgComponent = (
        <SettingDialog ecId={`${this && this.props && this.props.ecId || ''}_SettingDialog@eeyoi1`} 
          title={title}
          type={type}
          settingData={settingData} 
          dialogHeight={dialogHeight}
          onCancel={this.setdgVisible.bind(this, false)}
          onOk={this.onOk}
        />
      )
    } 
    return (
      <div className='com-ele-toolbar'>
        <ul>
            {refresh && <li>
                            <a href="javascript:void(0);" name="refreshbtn"  onClick={doRefresh} title={getLabel(515561,'刷新')}>
                              <i className="icon-coms-Synchro" />
                            </a>
                          
                        </li> }
            {setting && <li>
                            <a href="javascript:void(0)" onClick={this.onSettingBtnClick} title={getLabel(518821,'设置')}>
                              <img src='/images/ecology9/workflow/center/toolbar/setting_wev8.png' border="0" alt=''/>
                            </a>
                        </li> }
            {more && <li>
                            <a href="javascript:void(0);" onClick={moreBtnClick} title={getLabel(518820,'更多')}>
                              <img src='/images/ecology9/workflow/center/toolbar/more_wev8.png' border="0" alt=''/>
                            </a>
                        </li> }        
        </ul>
        {dgComponent}
      </div>
    )
  }
}

export default ToolBar